﻿using AutoMapper;
using MediatR;
using SU.Center.Domain.SY;
using SU.Center.Infa;

namespace SU.Center.Api.Handler.TraceabilityMethod
{
    /// <summary>
    /// 新增产品信息
    /// </summary>
    public class InsetInformationHandler : IRequestHandler<InsetInformationDto, ApiResult>
    {
        private readonly ILogger<InsetInformationHandler> logger;
        private readonly IBaseReposiotry<Information> baseReposiotry;
        private readonly IMapper mapper;

        public InsetInformationHandler(ILogger<InsetInformationHandler> logger, IBaseReposiotry<Information> baseReposiotry, IMapper mapper)
        {
            this.logger = logger;
            this.baseReposiotry = baseReposiotry;
            this.mapper = mapper;
        }

        public async Task<ApiResult> Handle(InsetInformationDto request, CancellationToken cancellationToken)
        {
            var list = mapper.Map<Information>(request);            
            var user = await baseReposiotry.InsetAsync(list);
            return ApiResult.Ok("新增产品信息成功");
        }
    }
}

public class InsetInformationDto : IRequest<ApiResult>
{
    /// <summary>
    ///产品外键
    /// </summary>
    public int ProductId { get; set; }
    /// <summary>
    /// 生产批次
    /// </summary>
    public string InformationBatch { get; set; }
    /// <summary>
    /// 保质期（天）
    /// </summary>
    public string InformationDay { get; set; }
    /// <summary>
    /// 生产许可证号
    /// </summary>
    public string InformationCertificate { get; set; }
    /// <summary>
    /// 生产企业
    /// </summary>
    public string InformationEnterprise { get; set; }
    /// <summary>
    /// 封面
    /// </summary>
    public string InformationCover { get; set; }
}
